package net.loyintean.pearlshell.validation.rule;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.loyintean.pearlshell.validation.IValidRule;
import net.loyintean.pearlshell.validation.IValidRuleConfig;

//2014-7-9 from林俊 to辰明 same to idcard start
//CLOSE same to what I comment in StringIdentifyCardValidRuleImpl
//2014-7-9 from林俊 to辰明 same to idcard end

class StringPhoneNumValidRuleImpl extends AbstractStringValidRuleImpl implements
		IValidRule {
	StringPhoneNumValidRuleImpl() {
		super();
	}

	private static final Pattern PhoneNum = Pattern
			.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");

	@Override
	public String errorMsg(IValidRuleConfig config) {
		return "不符合手机号码的格式";
	}

	@Override
	protected boolean validString(String toValid, IValidRuleConfig config) {
		Matcher phone_num = PhoneNum.matcher(toValid);
		return phone_num.find();
	}

}
